package com.laery0.xixin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.laery0.xixin.mapper.HospitalMapper;
import com.laery0.xixin.po.Hospital;
import com.laery0.xixin.po.ResponseBean;
import com.laery0.xixin.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HospitalServiceImpl implements HospitalService {
    @Autowired
    private HospitalMapper hospitalMapper;

    @Override
    public ResponseBean<List<Hospital>> listHospital(Integer state) {
        QueryWrapper<Hospital> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", state);
        List<Hospital> hospitalList = hospitalMapper.selectList(queryWrapper);
        if (hospitalList.size() > 0) {
            return new ResponseBean<>(hospitalList);
        } else {
            return new ResponseBean<>(601, "未查询到状态为"+ ((state==1) ? "正常" : "异常") + "的医院");
        }
    }

    @Override
    public ResponseBean<Hospital> getHospitalById(Integer hpId) {
        Hospital hospital = hospitalMapper.selectById(hpId);
        if (hospital != null) {
            return new ResponseBean<>(hospital);
        } else {
            return new ResponseBean<>(601, "未找到id为" + hpId + "的医院");
        }
    }
}
